package com.privatbank.servlets;

import com.privatbank.constants.Constants;
import com.privatbank.tables.Category;
import com.privatbank.Dao.CategoryDao;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Slava on 26.07.2014.
 */
public class JspCategoryList extends HttpServlet {
    private CategoryDao dao = null;


    public void init() {
        dao = new CategoryDao(Constants.LOGIN, Constants.PASSWORD, Constants.URL);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        List<Category> categories = null;
        try {
            categories = dao.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }


        request.setAttribute("categories", categories);
        RequestDispatcher dispatch = request.getRequestDispatcher("WEB-INF/jsp/categoryList.jsp");
        dispatch.forward(request, response);
    }
}
